package com.example.test622.ui.home

import android.util.Log
import android.widget.Toast
import com.example.common.mvi.BaseFragment
import com.example.net.Dao.DataBase
import com.example.test622.App
import com.example.test622.databinding.FragmentHomeBinding
import com.google.android.material.tabs.TabLayoutMediator

class HomeFragment : BaseFragment<FragmentHomeBinding,HomeViewModel>() {
	val adapter by lazy { TabAdapter(f = this) }
	
	override fun initView() {
		binding.vp2Home.adapter = adapter
		binding.vp2Home.isSaveEnabled = false
		TabLayoutMediator(binding.tabHome,binding.vp2Home){tab,p->
			tab.text = adapter.getTitle(p)
		}.	attach()
//		binding.tv1.setOnClickListener {
//			val web = UMWeb("https://www.baidu.com/")
//		web.setTitle("This is music title")//标题
////                web.setThumb(thumb);//缩略图
//		web.setDescription("my description")//描述
//		ShareAction(activity)
//			.withMedia(web)
//			.setDisplayList(SHARE_MEDIA.QQ, SHARE_MEDIA.WEIXIN)
//			.open()
//		}
	}
	
	override fun initData() {
			viewModel.state.observe(this){
				when(it){
					is HomeState.LoadSuccess->{
						Log.d("eee", "initData: "+it.videoType.data)
						adapter+=it.videoType.data
					}
					is HomeState.loadFail->{
						Log.d("eee", "initData: "+it.error)
						Toast.makeText(requireContext(),it.error,Toast.LENGTH_SHORT).show()
					}
				}
			}
		viewModel.intent.trySend(HomeIntent.getVideoType)
	}
	
}